

from cfcall.cfgseg import cfgsegbase

from cfcall.utils import aptutils
from cfcall.etcdb import md5db

class cfgETC(cfgsegbase.cfgSeg):
    
    files = [ "/etc/apt/apt.conf",
              "/etc/ssh/ssh_config",
              "~/.pip/pip.conf",
              "~/.bashrc",
              "/etc/tsocks.conf"
            ]
    usrf = []
    changedf = []
    
    
    def info(self):
        print "--------------------"
        print "etc files check"

    def _check(self, f):
        md5_sys = None
        pkg =  aptutils.find_pkg_by_file(f)
        
        if pkg is None:
            # usr created
            self.usrf.append(f)
        else:
            md5_sys = md5db.get_cached_md5(pkg, f)
            md5 = aptutils.calc_md5(f)
            if md5_sys != md5:
                self.changedf.append(f)

    def check(self):
        
        # find pkg name we want to check
        for f in self.files:
            self._check(f)
        
        return True
    
    def save(self):
        print "changed", self.changedf
        print "usrf", self.usrf
        
        return True
